﻿using System;

namespace MsTestUtilities.SolutionAnalysis
{
    public class ContentFile : IItem
    {
        private const string CopyElementName = "CopyToOutputDirectory";

        private Item _item;

        public const string ElementName = "Content";

        public string Path { get; private set; }

        public CopyToOutputDirectory CopyToOutputDirectory { get; private set; }

        public CsProject ParentProject { get; private set; }

        public ContentFile(CsProject project, Item item)
        {
            _item = item;
            if (item.Name != ElementName)
            {
                throw new ArgumentException(string.Format("Not a valid Content file element: '{0}'", item.Name));
            }

            Path = item.Include;
            ParentProject = project;
            if (item.Metadata.ContainsKey(CopyElementName))
            {
                CopyToOutputDirectory = CopyToOutputDirectory.Parse(item.Metadata[CopyElementName]);
            }
            else
            {
                CopyToOutputDirectory = CopyToOutputDirectory.Never;
            }
        }

        public string Include
        {
            get { return _item.Include; }
        }
    }
}
